import 'package:lishopflu/base/controller_import.dart';
import 'package:lishopflu/base/view_import.dart';
import 'package:lishopflu/global/my_theme_data.dart';
import 'package:lishopflu/global/theme_colors.dart';
import 'package:lishopflu/utils/sp_key.dart';
import 'package:lishopflu/utils/toast_util.dart';
//import 'package:provider/provider.dart';


class MainDrawer {

  BuildContext context;
  static String name = '点击头像登录';

  MainDrawer(this.context);

  Widget _drawerHerder(){
    name = 'Name';
    return UserAccountsDrawerHeader(
      accountName: Text(name),
      accountEmail: Text(name+'-email@163.com'),
      currentAccountPicture: CircleAvatar(
        backgroundImage: AssetImage('images/about_github.png'),
        child: GestureDetector(
          onTap: (){

          },
          child: Padding(padding: EdgeInsets.all(5),child: Text('未登录', style: TextStyle(color: Colors.red),),),
        ),
      ),
      onDetailsPressed: (){
        ToastUtil.toast('点击了');
        print('点击');
      },
    );
  }

  void showThemeDialog() {
    showModalBottomSheet(
      context: context,
//      barrierDismissible: false, // user must tap button!
      builder: (BuildContext context) {
        return Container(
          padding: EdgeInsets.all(20.0),
          child: SingleChildScrollView(
            child: Container(
              //包含ListView要指定宽高
              width: MediaQuery.of(context).size.width * 0.6,
              height: MediaQuery.of(context).size.height * 0.5,
              child: ListView.builder(
                shrinkWrap: true,
                itemCount: THColors.themeColor.keys.length,
                itemBuilder: (BuildContext context, int position) {
                  String _key = THColors.themeColor.keys.elementAt(position);
                  return GestureDetector(
                    child: Container(
                      padding: EdgeInsets.all(20.0),
                      margin: EdgeInsets.only(bottom: 15),
                      color: THColors.themeColor[_key]//["primaryColor"],
                    ),
                    onTap: () async {
//                      Provider.of<ThemeProvide>(context, listen: false).setTheme(_key);
                      Get.changeTheme(MyThemeData.appTheme(THColors.themeColor[_key]));
                      //存储主题下标
                      SPKey.spSetStr(SPKey.themeIndex, _key);
                      Navigator.of(context).pop();
                    },
                  );
                },
              ),
            ),
          ),
        );
      },
    );
  }

  Widget homeDrawer(){
    return ListView(
      padding: EdgeInsets.all(0.0),
      children: <Widget>[

        _drawerHerder(),

        Container(
          decoration: BoxDecoration(
            border: Border(
                bottom: Divider.createBorderSide(context,color: Colors.green,width: 1)
            ),
          ),
          child: ListTile(
            leading: CircleAvatar(child: Text('藏'),),
            title: Text('收藏列表'),
            onTap: (){

            },
          ),
        ),

        Container(
          decoration: BoxDecoration(
            border: Border(
                bottom: Divider.createBorderSide(context,color: Colors.green,width: 1)
            ),
          ),
          child: ListTile(
            leading: CircleAvatar(child: Text('本'),),
            title: Text('本地收藏'),
            onTap: (){

            },
          ),
        ),

        Container(
          decoration: BoxDecoration(
            border: Border(
                bottom: Divider.createBorderSide(context,color: Colors.green,width: 1)
            ),
          ),
          child: ListTile(
            leading: CircleAvatar(child: Text('分'),),
            title: Text('积分排行榜'),
            onTap: (){

            },
          ),
        ),

        Container(
          decoration: BoxDecoration(
            border: Border(
                bottom: Divider.createBorderSide(context,color: Colors.green,width: 1)
            ),
          ),
          child: ListTile(
            leading: CircleAvatar(child: Text('切'),),
            title: Text('切换主题'),
            onTap: (){
              print('切换主题');
              showThemeDialog();
              /*showModalBottomSheet(
                  context: context,
                  builder: (BuildContext context) {
                    return _themeWidget(context);
                  });*/
            },
          ),
        ),

        Container(
          decoration: BoxDecoration(
            border: Border(
                bottom: Divider.createBorderSide(context,color: Colors.green,width: 1)
            ),
          ),
          child: ListTile(
            leading: CircleAvatar(child: Text('退'),),
            title: Text('退出登录'),
            onTap: (){

            },
          ),
        ),

      ],
    );
  }

  Widget _themeWidget(BuildContext context) {
    String _colorKey;
    return new Container(
      height: 250.0,
      child: new Column(
        children: <Widget>[
          new Padding(
            padding: EdgeInsets.fromLTRB(0.0, 10.0, 0.0, 0.0),
            child: new Container(
              height: 190.0,
              child: SingleChildScrollView(
                child: Container(
                  //包含ListView要指定宽高
                  width: MediaQuery.of(context).size.width * 0.6,
                  height: MediaQuery.of(context).size.height * 0.5,
                  child: ListView.builder(
                    shrinkWrap: true,
                    itemCount: THColors.themeColor.keys.length,
                    itemBuilder: (BuildContext context, int position) {
                      return GestureDetector(
                        child: Container(
                          padding: EdgeInsets.all(20.0),
                          margin: EdgeInsets.only(bottom: 15),
                          color: THColors.themeColor[position],//["primaryColor"],
                        ),
                        onTap: () async {
//                          Provider.of<ThemeProvide>(context, listen: false).setTheme(THColors.themeColor.keys.elementAt(position));
                          Get.changeTheme(MyThemeData.appTheme(THColors.themeColor[position]));
                          //存储主题下标
                          SPKey.spSetInt(SPKey.themeIndex, position);
                          Navigator.of(context).pop();
                        },
                      );
                    },
                  ),
                ),
              ),
            ),
          ),
          new Container( height: 0.5, color: Colors.blueGrey, ),
          new Center( child: new Padding(
              padding: EdgeInsets.fromLTRB(0.0, 8.0, 0.0, 8.0),
              child: new Text( '取  消', style: new TextStyle(fontSize: 18.0, color: Colors.blueGrey), ) ), )
        ],
      ),
    );
  }
}